package com.yuejian_06.yuejian_06.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;
import com.yuejian_06.yuejian_06.Listener.LoginListener;
import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.bean.CourseBean;
import com.yuejian_06.yuejian_06.fragment.Constants;
import com.yuejian_06.yuejian_06.fragment.Constants_l;
import com.yuejian_06.yuejian_06.model.CourseModel;

public class CourseInfoActivity extends BaseActivity {
    TextView course_name,course_info,course_starttime,course_stoptime,course_address,course_tele,course_start,course_know,course_price;
    Button course_ording,course_ask;
    ImageView course_pic;
    String course_id;
    ImageButton course_back;
    String phone;


    private LoginListener<CourseBean> Listener=new LoginListener<CourseBean>() {
        @Override
        public void onResponse(CourseBean o) {
            CourseBean mDataList=o;
            phone = mDataList.getPhone().toString();
            course_name.setText(mDataList.getName());
            course_info.setText(mDataList.getIntro());
            course_know.setText(mDataList.getKnow());
            course_address.setText(mDataList.getAddress());
            course_tele.setText(mDataList.getPhone());
            course_price.setText("¥"+mDataList.getPrice());
            course_starttime.setText(mDataList.getStarttime1());
            course_stoptime.setText(mDataList.getStoptime());
            course_start.setText(mDataList.getStarttime());
            String internetUrl = Constants.SSS+"yuejian/Public/coursepics/"+mDataList.getPic().toString();
            if(!mDataList.getPic().isEmpty())
            {
                Picasso
                        .with(CourseInfoActivity.this)
                        .load(internetUrl)
                        .into(course_pic);}
            else
            {
                course_pic.setImageResource(R.drawable.club_wu);
            }

        }
        @Override
        public void onFail(String msg) {
            Toast.makeText(getApplicationContext(),"失败了"+course_id,Toast.LENGTH_SHORT).show();

        }
    };

    @Override
    void initViews() {
        setLayout(R.layout.activity_course_info);
        course_name=(TextView)findViewById(R.id.course_info_name);
        course_info=(TextView)findViewById(R.id.course_info_info);
        course_know=(TextView)findViewById(R.id.course_info_know);
        course_start=(TextView)findViewById(R.id.course_info_start);
        course_starttime=(TextView)findViewById(R.id.course_info_starttime);
        course_stoptime=(TextView)findViewById(R.id.course_info_stoptime);
        course_address=(TextView)findViewById(R.id.course_info_address);
        course_tele=(TextView)findViewById(R.id.course_info_tele);
        course_price=(TextView)findViewById(R.id.course_info_price);
        course_ording=(Button)findViewById(R.id.course_info_ording);
        course_ask=(Button) findViewById(R.id.course_info_ask);
        course_pic=(ImageView)findViewById(R.id.course_info_pic);
        course_back=(ImageButton)findViewById(R.id.course_info_back);
        Bundle bundle = getIntent().getExtras();
        course_id = bundle.getString("course_id");
    }

    @Override
    void initEvents() {
        CourseModel courseModel=new CourseModel();
        courseModel.courseInfo(course_id,Listener);
    }

    @Override
    void initData() {
        course_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        course_ask.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CallDialog dialog=new CallDialog();
                dialog.showCallPhoneDialog(CourseInfoActivity.this,phone);
            }
        });
        course_ording.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(CourseInfoActivity.this, OrderingActivity.class);
                intent.putExtra("course_id",course_id);
                startActivity(intent);
            }
        });
    }

}
